import 'package:app/common/colors.dart';
import 'package:app/common/tool.dart';
import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/components/nodata_page.dart';
import 'package:app/pages/car_modules/car_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';

import 'car_model.dart';

class CarView extends GetView{


  CarController controller = Get.put(CarController());


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: BaseAppBar(
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
        child: Text('所有车辆'),
      ),
      body:GetBuilder<CarController>(builder: (_){
        return  EasyRefresh.custom(
          onRefresh:() => controller.onRefresh(),
          onLoad: () => controller.onLoad(),
          emptyWidget: controller.dataArr.isEmpty?NoDataPage():null,
          slivers: [
            SliverList(delegate: _mySliverChildBuilderDelegate(),)
          ],
        );
      })
    );
  }
  _mySliverChildBuilderDelegate() {
    return SliverChildBuilderDelegate(
          (BuildContext context, int index) {

            CarItemModel model = controller.dataArr[index];

        return GestureDetector(
          onTap: (){
            Get.back(result: {'name':model.name,'id':model.id});
          },
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: Get.width,
                color: Colors.white,
                  padding: EdgeInsets.all(10),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Text('车辆名称:${model.name}'),
                          SizedBox(width: 15,),
                          Text('车牌号码:${model.number??''}'),
                        ],
                      ),
                      Row(
                        children: [
                          Text('车辆型号:${model.model??''}'),
                          SizedBox(width: 15,),
                          Text('类型:${model.type??''}'),
                        ],
                      ),
                    ],
                  )
              ),
              Container(
                color: AppColor.lineColor,
                height: 0.5,
              )
            ],
          ),
        );
      },
      childCount: controller.dataArr.length,
    );
  }

}